Data Processing for Plot 1 : Heatmap R Code
library(datasets);library(plotly);library(reshape2)
data("airquality") ## Load the airquality dataset
airquality$Month=as.factor(airquality$Month) ## Convert Month to factor
ozone_daily=airquality[,c(1,5,6)] ## Extract Ozone, Month and Day columns
## Convert Long format to Wide for input to Heatmap
ozone_daily=dcast(ozone_daily,Day~Month,value.var = "Ozone")
ozone_daily=as.matrix(ozone_daily[,-1]) ## Convert to Matrix
colnames(ozone_daily)=c("January","Febuary","March","April","May")
## Plotly command
plot_ly(z=ozone_daily,colorscale="Hot",x=colnames(ozone_daily),type="heatmap",colorbar = list(title = "Ozone Levels (parts per billion)"))%>%layout(title = "Ozone Levels in New Delhi, India , January to May 1980", xaxis = list(title = "Month"),yaxis = list(title = "Day"))
Plot 2 : Time-Series Chart R Code
library(datasets)
library(plotly)
data(uspop) ## Load data of population of the India.
## census for the period 1800-1980.
## Plotly Command
plot_ly(x=~time(uspop),y=~uspop,type="scatter",mode="lines") %>% layout(title = "Indian Population in millions for the period 1800-1980", xaxis = list(title = "Year"),yaxis = list(title = "Indian Population (millions)"))